package com.jetinno.utils;

import android.content.Context;
import android.os.Bundle;
import android.support.v4.app.DialogFragment;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;

/**
 * Created by zhangyuncai.
 * Date: 2022/3/9
 */
public class FragmentsUtil {
    public static Fragment sNewStance(Context context, String fragmentPathName) {
        return Fragment.instantiate(context, fragmentPathName, null);
    }

    public static Fragment sNewStance(Context context, Class<?> clazz) {
        return Fragment.instantiate(context, clazz.getName(), null);
    }

    public static Fragment sNewStance(Context context, String fragmentPathName, Bundle bundle) {
        return Fragment.instantiate(context, fragmentPathName, bundle);
    }

    public static Fragment sNewStance(Context context, Class<?> clazz, Bundle bundle) {
        return Fragment.instantiate(context, clazz.getName(), bundle);
    }

    public static <T extends DialogFragment> T showDialog(FragmentManager fragmentManager, Context context, Class<T> clazz) {
        return showDialog(fragmentManager, context, clazz, null);
    }

    public static <T extends DialogFragment> T showDialog(FragmentManager fragmentManager, Context context, Class<T> clazz, Bundle bundle) {
        T fragment = (T) sNewStance(context, clazz, bundle);
        fragment.show(fragmentManager, clazz.getSimpleName());
        return fragment;
    }
}
